// pages/mine/mine.js

var app = getApp(); 
//HTTP请求request封装
var HttpRequest = require("../../http.js");
//CBC加密 
var CryptoJS = require("../../Crypto.js");
//RSA加密
var RSA = require("../../rsa.js"); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone_text: '*********',
    phone_status: '您尚未完成实名认证',
    touxImg:'../image/tx.png',
  },

  getReq: HttpRequest.getReq,//GET数据请求函数
  postReq: HttpRequest.postReq,//POST数据请求 

  //跳转健康卡
  clickhealth:function(){
    wx.switchTab({
      url: '../Health/Health'
    })
  },
  //跳转二维码
  clickmine:function(){
    wx.navigateTo({
      url: '../micro/micro'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    //随机私钥  
    const key = CryptoJS.enc.Utf8.parse(app.globalData.PrivateKey);
    console.log("随机私钥:" + key);

    //加密偏移量
    const options = {
      iv: CryptoJS.enc.Utf8.parse("bskyapp123456789"),
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    };
    if (getApp().globalData.LoginStatus == false) {
      wx.showModal({
        title: '温馨提示',
        content: '您还未登录，请先登录！',
        showCancel: false,
        success: function (v) {
          wx.redirectTo({
            url: '../logIn/logIn'
          })
        }
      })
    }else{
      var login_Info = JSON.parse(wx.getStorageSync('login_Information')); //登录基础信息   
      console.log(login_Info); 
      const headArray = wx.getStorageSync('UserLogin');
      const headmode = {
        'Accept': 'application/json',
        "Content-Type": "application/x-www-form-urlencoded",
        "headMode": headArray,
        "token": login_Info.token,
      };
      const infoUrl = '/resident/info/v20171206'
      HttpRequest.getReq(infoUrl, getApp().globalData.data , headmode, function (res, code) {
        console.log(res);
        var verifStatus = res.verifStatus;
        //CBC解密用户姓名
        var decryptedData = CryptoJS.AES.decrypt(res.realName, key, options);
        var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
        console.log('CBC解密：', decryptedStr);
        var realName = decryptedStr;
        const dictUrl = '/allreq/dict/typeDict?dictTypes=auth_status';
        HttpRequest.getReq(dictUrl, getApp().globalData.data, headmode, function (res, code) {
          console.log(res);
          var data_list = res;
            for (let i in data_list){ 
              var lebel = data_list[i].dictList;
              console.log('获取的实名认证编码', verifStatus);
              for (let j in lebel){
                if (lebel[j].value == verifStatus){ 
                  var StatusTxte = lebel[j].lebel
                  that.setData({
                    phone_text: realName,
                    phone_status: StatusTxte
                  })
                  return false;
                }
              }
            }
        });
      });
    }
  },
})